package main

import "fmt"

//map 切片，函数不能作为键值
func main() {
	//map 只有len 没有cap
	var m1 map[int]string
	fmt.Printf("m1=%v\n", m1)
	//可以通过make创建
	m2 := make(map[int]string)
	m2[1] = "mike"
	m2[2] = "tom"
	m2[3] = "lily"
	fmt.Printf("m2=%v\n", m2)
	//初始化键值是唯一的
	m3 := map[int]string{1: "c++", 2: "java", 3: "go"}
	fmt.Printf("m3=%v\n", m3)
	m3[4] = "html" //map底层会自动扩容，和append类似
	fmt.Printf("m3=%v\n", m3)

	//map 循环
	for key, val := range m3 {
		fmt.Printf("key=%v,val=%v\n", key, val)
	}
	//判断
	value, ok := m3[88]
	if ok == true {
		fmt.Printf("m3[88]=%v\n", value)
	} else {
		fmt.Println("no value")
	}
	//删除
	delete(m3, 1)
	fmt.Printf("m3=%v\n", m3)
	//map做参数是引用传递
}
